package br.com.esporte.view.infra.security;

import org.apache.wicket.Component;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.IAuthorizationStrategy;
import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener;
import org.springframework.stereotype.Service;

/**
 * 
 * @author Milton Domingues
 * 
 */
@Service
public class EsporteAuthorizationStrategy implements IUnauthorizedComponentInstantiationListener, IAuthorizationStrategy {

	private static EsporteAuthorizationStrategy instance;

	public static EsporteAuthorizationStrategy getInstance() {
		if (instance == null) {
			instance = new EsporteAuthorizationStrategy();
		}
		return instance;
	}

	private EsporteAuthorizationStrategy() {
	}

	@Override
	public boolean isActionAuthorized(final Component component, final Action action) {
		return true;
	}

	@Override
	@SuppressWarnings("rawtypes")
	public boolean isInstantiationAuthorized(final Class componentClass) {
		/*if (PaginaTemplate.class.isAssignableFrom(componentClass)) {
			return SessionEsporte.get().isAuthenticated();
		} else {
			return true;
		}*/
		return true;
	}

	@Override
	public void onUnauthorizedInstantiation(final Component component) {
		//throw new RestartResponseAtInterceptPageException(PaginaLogin.class);
	}
}